package logic

import (
	"context"

	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysRoleSelectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysRoleSelectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysRoleSelectLogic {
	return &SysRoleSelectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysRoleSelectLogic) SysRoleSelect(in *sys.SysRoleSelectReq) (*sys.SysRoleSelectRes, error) {

	all, err := l.svcCtx.SysRoleModel.Find(l.ctx, "")
	if err != nil {
		return nil, err
	}

	var list = make([]*sys.SysRoleInfo, len(all))
	for i, v := range all {
		list[i] = &sys.SysRoleInfo{
			Id:       v.Id,
			RoleName: v.RoleName,
			Remark:   v.Remark,
		}
	}

	return &sys.SysRoleSelectRes{
		List: list,
	}, nil
}
